/**
 * Author: w景洋.
 * Time: 2016/7/6 0006
 */
angular.module('service_class.ccsb', [

    ])

    .config(['$stateProvider','$urlRouterProvider',
        function($stateProvider, $urlRouterProvider) {
            $stateProvider

                .state('model.ccsb-jr', {
                    url: '/ccsb-jr',
                    templateUrl: service_templateprefix + "service_class/ccsb-jr.html",
                    controller: 'Ccsb-jrController'
                })
                .state('model.ccsb-qx', {
                    url: '/ccsb-qx',
                    templateUrl: service_templateprefix + "service_class/ccsb-qx.html",
                    controller: 'Ccsb-qxController'
                })
                .state('model.devinfo2',{//设备信息————————————全新与二手共用一组数据
                    url : '/devinfo?dId',
                    templateUrl : service_templateprefix + "service_class/devinfo.html",
                    controller : 'DevinfoController'
                })
                .state('model.ccsb-es', {
                    url: '/ccsb-es',
                    templateUrl: service_templateprefix + "service_class/ccsb-es.html",
                    controller: 'Ccsb-esController'
                })
                .state('model.devtrans',{//设备转让信息
                    url : '/devtrans',
                    templateUrl : service_templateprefix + "service_class/devtrans.html",
                    controller : 'DevtransController'
                })
                .state('model.devinfo',{//设备信息
                    url : '/devinfo?dId',
                    templateUrl : service_templateprefix + "service_class/devinfo.html",
                    controller : 'DevinfoController'
                })

        }])

    .controller('Ccsb-jrController', ['$scope', '$state','adService', function($scope,$state,adService) {

    }])
    .controller('Ccsb-qxController',['$scope', '$state', 'SbzrService', 'DevinfoService','$stateParams',
        function($scope,$state,SbzrService,DevinfoService,$stateParams) {
            console.log("12")
            $scope.searchDev='';
            $scope.devlist = SbzrService.getSbzrList();
            $scope.devlist.$promise.then(function(list){
                console.log(list)
                $scope.sbzrlist=list;
                //console.log($scope.devlist[0].name);
            });
            //分页
            $scope.currentPage = 1;
            $scope.pageSize = 8;

            $scope.name='';
            $scope.getPagingSearchList=function(){
                SbzrService.getPagingSearchList($scope.name).$promise.then(function(data){
                    $scope.sbzrlist=[];
                    $scope.sbzrlist=data;
                })
            }
            //searchDev
            $scope.aplitsearchDev=function(searchDev){
                $scope.name = searchDev;
                $scope.getPagingSearchList();
            }

            $scope.show_hide = function(dId){
                click_show(".home_carouse2","#hidval")
                $scope.devinfolist = DevinfoService.getDevinfoList(dId);
            }

        }])

    //设备信息
    .controller('DevinfoController',['$scope', '$state', 'DevinfoService','$stateParams',
        function($scope,$state,DevinfoService,$stateParams) {
            $scope.devinfolist = DevinfoService.getDevinfoList($stateParams.dId);
            $scope.devinfolist.$promise.then(function(list){
                //console.log($scope.devinfolist.name);
            });
        }])

    .controller('Ccsb-esController',['$scope', '$state', 'SbzrService', 'DevinfoService','$stateParams',
        function($scope,$state,SbzrService,DevinfoService,$stateParams) {
            $scope.searchDev='';
            $scope.devlist = SbzrService.getSbzrList();
            $scope.devlist.$promise.then(function(list){
                console.log(list)
                $scope.sbzrlist=list;
                //console.log($scope.devlist[0].name);
            });
            //分页
            $scope.currentPage = 1;
            $scope.pageSize = 8;

            $scope.name='';
            $scope.getPagingSearchList=function(){
                SbzrService.getPagingSearchList($scope.name).$promise.then(function(data){
                    $scope.sbzrlist=[];
                    $scope.sbzrlist=data;
                })
            }
            //searchDev
            $scope.aplitsearchDev=function(searchDev){
                $scope.name = searchDev;
                $scope.getPagingSearchList();
            }

            $scope.show_hide = function(dId){
                click_show(".home_carouse2","#hidval")
                $scope.devinfolist = DevinfoService.getDevinfoList(dId);
            }

        }])
    //设备转让信息
    .controller('DevtransController', ['$scope', '$state', 'DevtransService', 'fileUpload',
        function($scope,$state,DevtransService,fileUpload) {

            $scope.devtrans = "";
            $scope.putDevtransInfo=function(){
                $scope.success_func = function(){//提交成功回调函数
                    $state.go("model.sbzr");
                }
                $scope.error_func = function(data){//提交失败回调函数
                    alert(data.data.reason);
                }
                DevtransService.putDevtransInfo($scope.devtrans,$scope.success_func,$scope.error_func);
            };

            $scope.uploadFile = function(){

                if($scope.myFile==undefined){
                    alert("请选择图片！");
                    return;
                }
                var file = $scope.myFile;
                fileUpload.uploadFileToUrl(file).then(function(data){
                    $scope.devtrans.logo = data;
                    if(data!=undefined){
                        return;
                    }
                });
            };

            $scope.uploadFile_photo1 = function(){
                if($scope.myFile_photo1==undefined){
                    alert("请选择图片！");
                    return;
                }
                var file = $scope.myFile_photo1;
                fileUpload.uploadFileToUrl(file).then(function(data){
                    $scope.devtrans.photo1 = data;
                    if(data!=undefined){
                        return;
                    }
                });
            };
            $scope.uploadFile_photo2 = function(){
                if($scope.myFile_photo2==undefined){
                    alert("请选择图片！");
                    return;
                }
                var file = $scope.myFile_photo2;
                fileUpload.uploadFileToUrl(file).then(function(data){
                    $scope.devtrans.photo2 = data;
                    if(data!=undefined){
                        return;
                    }
                });
            };
        }])
    //设备信息
    .controller('DevinfoController',['$scope', '$state', 'DevinfoService','$stateParams',
        function($scope,$state,DevinfoService,$stateParams) {
            $scope.devinfolist = DevinfoService.getDevinfoList($stateParams.dId);
            $scope.devinfolist.$promise.then(function(list){
                //console.log($scope.devinfolist.name);
            });
        }])


//设备转让购买显示隐藏
function click_show(){
    //if ($(c).val() == 0) {
    //    $(b).show()
    //    $(c).val(1)
    //}else {
    //    $(b).hide()
    //    $(c).val(0)
    //}

    $('.home_carouse2').show()
};
function click_hide(){
    $('.home_carouse2').hide()
}
